# ##### BEGIN GPL LICENSE BLOCK #####
#
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License
#  as published by the Free Software Foundation; either version 2
#  of the License, or (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software Foundation,
#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####

# <pep8 compliant>

bl_info = {
    "name": "JavaScript format",
    "description": "Import-Export JavaScript",
    "author": "Peter Davies, Andrew",
    "version": (1, 0),
    "blender": (2, 64, 0),
    "location": "File > Export > Export JavaScript (.js)",
    "warning": "",
    "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/Scripts/Import-Export/JavaScript",
    "tracker_url": "",
    "category": "Import-Export"}

# To support reload properly, try to access a package var, if it's there, reload everything
if "bpy" in locals():
    import imp
    if "export_javascript" in locals():
        imp.reload(export_javascript)


import bpy
from bpy.props import (StringProperty,BoolProperty,FloatProperty,EnumProperty)
from bpy_extras.io_utils import (ExportHelper,path_reference_mode,axis_conversion)

class ExportJavaScript(bpy.types.Operator, ExportHelper):
    '''Export selection to JavaScript file (.js)'''
    bl_idname = "export_scene.javascript"
    bl_label = "Export JavaScript"

    filename_ext = ".js"
    filter_glob = StringProperty(default="*.js", options={'HIDDEN'})

    use_selection = BoolProperty(name="Selection Only", description="Export selected objects only", default=False)
    use_apply_modifiers = BoolProperty(name="Apply Modifiers", description="Use transformed mesh data from each object", default=True)
    use_triangulate = BoolProperty(name="Triangulate", description="Triangulate quads.", default=False)

    def execute(self, context):
        from . import export_javascript
        return export_javascript.save(self, context, **self.as_keywords(ignore=("check_existing", "filter_glob")))

def menu_func_export(self, context):
    self.layout.operator_context = 'INVOKE_DEFAULT'
    self.layout.operator(ExportJavaScript.bl_idname, text="JavaScript (.js)")

def register():
    bpy.utils.register_class(ExportJavaScript)
    bpy.types.INFO_MT_file_export.append(menu_func_export)

def unregister():
    bpy.types.INFO_MT_file_export.remove(menu_func_export)
    bpy.utils.unregister_class(ExportJavaScript)

# NOTES
# - blender version is hardcoded

if __name__ == "__main__":
    register()
	